package com.friend.chat.page.vm

import androidx.lifecycle.MutableLiveData
import com.friend.chat.net.BaseResult
import com.friend.chat.base.BasicViewModel

/**
 * @des
 * @author batie fancy
 * @date 2022/12/31
 */
class RegisterViewModel: BasicViewModel()  {
    val uploadPicResponse by lazy { MutableLiveData<BaseResult<String>>() }
    val registerResponse by lazy { MutableLiveData<BaseResult<Boolean>>() }
    fun uploadHeader(path:String) {
        netWorkJob(
            successResult = {
                val data = mRepository.uploadHeader(path)
                if (!data.isOk()) {
                    toast(data.message)
                } else {
                    uploadPicResponse.value = data
                }
            },
            errorResult = {
                toast("错误")
            }
        )
    }

    fun register(username:String,nickname:String,password:String,phone:String,header:String,sex:Int,age:Int){
        netWorkJob(
            successResult = {
                val data = mRepository.register(username, nickname, password, phone, header, sex, age)
                if (!data.isOk()) {
                    toast(data.message)
                } else {
                    registerResponse.value = data
                }
            },
            errorResult = {
                toast("错误")
            }
        )
    }


}